package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import com.itany.vo.UserPermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author：汤小洋
 * Date：2019-09-24 上午9:39
 * Description：<描述>
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;


    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows, Permission permission){

        Map<String,Object> map = new HashMap<String, Object>();
        PageInfo<Permission> info = permissionService.findAllBook(page, rows,permission);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }

    @RequestMapping("findAllParent")
    @ResponseBody
    public List<Permission> findAllParent(){
        List<Permission> permissions= permissionService.findAllParent();

        return permissions;
    }


    @RequestMapping("findAllParentById")
    @ResponseBody
    public List<UserPermissionVo> findAllParentById(Integer id){
        List<UserPermissionVo> permissionById = permissionService.findPermissionById(id);

        return permissionById;
    }



    //权限修改
    @RequestMapping("modifyPermission")
    public String modifyPermission(Permission permission,@RequestParam("myParentId") Integer parentId){
        permission.setParentId(parentId);

        permissionService.modifyPermission(permission);

        return "permission";
    }

} 